<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/icons-extra.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">	
			<a class="mui-icon mui-icon-back mui-action-back mui-pull-left"></a>
			<h1 class="mui-title ">IO</h1>
			<a class="mui-icon-extra mui-icon-extra-topic mui-pull-right" style="margin-top: 10px;"
				 onclick="openWindow('docIO','../doc/io.html?v=20190621')"></a>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<div class="mui-row">
					IO模块管理本地文件系统，用于对文件系统的目录浏览、文件的读取、文件的写入等操作。通过plus.io可获取文件系统管理对象。
				</div>
				<br />
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-success mui-btn-block" onclick="watchPos()">监听设备位置</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="clearWatch()">停止监听</button>
					<button type="button" class="mui-btn mui-btn-warning mui-btn-block" onclick="getGeocode()">获取定位信息</button>
				</div>
				<br />
				<div class="mui-row" id="divInfo" style="word-wrap:break-word">
					
				</div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			function outSet(message){
				document.getElementById("divInfo").innerText = message;
			}
			
			function outLine(message){
				var text = document.getElementById("divInfo").innerText;
				document.getElementById("divInfo").innerText = text + "\n" + message;
			}
			// Format data to string
			function dateToStr( datetime ) {
				var year = datetime.getFullYear(),
				month = datetime.getMonth()+1,
				date = datetime.getDate(),
				hour = datetime.getHours(),
				minutes = datetime.getMinutes(),
				second = datetime.getSeconds();
				if ( month < 10 ) {
					month = "0" + month;
				}
				if ( date < 10 ) {
					date = "0" + date;
				}
				if ( hour < 10 ) {
					hour = "0" + hour;
				}
				if ( minutes < 10 ) {
					minutes = "0" + minutes;
				}
				if ( second < 10 ) {
					second = "0" + second;
				}
				return (year+"-"+month+"-"+date+" "+hour+":"+minutes+":"+second);
			}
			mui.plusReady(function(){
				outSet("开始读取文件...");
				var filePath = [{id:"_www"},{id:"_doc"},{id:"_documents"},{id:"_downloads"}];
				//var item = {id:"_www"};
				filePath.forEach(function(item){
					plus.io.resolveLocalFileSystemURL(item.id, function ( entry ) {
						outLine("更新内容。。。");
						//root.push( entry );
						item.entry = entry;
						updateInf( item, entry );
					}, function ( e ) {
						outLine( "Update "+item.id+" information failed: "+e.message );
					} );
				});
			});
			
			function updateInf( item, entry ) {
				entry.getMetadata( function ( metadata ) {
					//var inf = item.querySelector(".finf");
					if ( entry.isDirectory ) {
						outLine("文件夹:"+metadata.directoryCount+"项，文件:"+metadata.fileCount+"项");
					} else {
						outLine(dateToStr(metadata.modificationTime));
					}
				}, function ( e ) {
					outLine( "Get metadata "+entry.name+" failed: "+e.message );
				}, false );
			}
		</script>
	</body>

</html>